# Maintainer: Tim Meusel <tim@bastelfreak.de>
pkgname=prometheus-wireguard-exporter
pkgver=3.6.6
pkgrel=1
pkgdesc='A Prometheus exporter for WireGuard, written in Rust.'
arch=('loong64' 'x86_64')
license=('MIT')
url='https://github.com/MindFlavor/prometheus_wireguard_exporter'
source=("${pkgname}-${pkgver}.tar.gz::https://static.crates.io/crates/prometheus_wireguard_exporter/prometheus_wireguard_exporter-${pkgver}.crate"
        'prometheus-wireguard-exporter.service'
        'prometheus-wireguard-exporter.conf'
        'prometheus-wireguard-exporter.sysusers'
        'prometheus-wireguard-exporter.install'
        )
install='prometheus-wireguard-exporter.install'
makedepends=(cargo)
depends=(wireguard-tools)
sha512sums=('81b6fa1b0fa0bef17a97d841b2fe42c88a80d4c5d0bca8d82aaf24e24b2eeefdac6e283c729aabc9c0c0420d5277d2bd0e733054ed286346f3db166c32858a8a'
            '9df12fd511a9a179351d46a9de1d439b72b7e9658ef2ae68d62e2ef9bbe6657707ff3aba36f45213caca1462a7bb85005b1ded2b924dbf40542ff930f0631155'
            '63520a99e021d7eaa53b7ea8d832698f116507ccba6d322cd33005c43aa1d65179437c0320662ba99fefe4e9bf23457bc3360dba22a4ee79d261dd21c2ba8074'
            '52c5e10f8d156efc18e1f44076023b36efb799d7446d016d07a9d8ff9480e49273878d1a460146d3300732f2a82e0608cbc5d4c04465640677d0a8b491368594'
            'fe8e41c85543a0e0d745aa57752f4139654547c9ae07cb4a8ac9d8679c8075f310bb0b6b73dc984cb52672b2416f364ce0371eaa16285e4ee3e576131f32f00c')

prepare() {
  cd "prometheus_wireguard_exporter-${pkgver}"
  cargo fetch --locked --target "$CARCH-unknown-linux-gnu"
}

build() {
  cd "prometheus_wireguard_exporter-${pkgver}"
  export RUSTUP_TOOLCHAIN=stable
  export CARGO_TARGET_DIR=target
  cargo build --frozen --release --all-features
}

check() {
  cd "prometheus_wireguard_exporter-${pkgver}"
  export RUSTUP_TOOLCHAIN=stable
  cargo test --frozen --all-features
}

package() {
  install -Dm644 prometheus-wireguard-exporter.service -t "${pkgdir}/usr/lib/systemd/system/"
  install -Dm644 prometheus-wireguard-exporter.conf "$pkgdir/etc/conf.d/prometheus-wireguard-exporter"
  install -Dm644 prometheus-wireguard-exporter.sysusers "${pkgdir}/usr/lib/sysusers.d/prometheus-wireguard-exporter.conf"

  cd "prometheus_wireguard_exporter-${pkgver}"
  install -Dm0755 'target/release/prometheus_wireguard_exporter' "$pkgdir/usr/bin/prometheus-wireguard-exporter"
  install -Dm644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}/"
  install -Dm644 README.md -t "${pkgdir}/usr/share/doc/${pkgname}/"
}
